﻿<div class="form-horizontal" ms-controller="JFBX">
    <div class="form-group">
        <label class="col-xs-2 control-label">表单申请人</label>
        <div class="col-xs-4">
            <p class="form-control-static" ms-text="modelData.ShenQingRen"></p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">报销时间</label>
        <div class="col-xs-4">
            <input type="text" ms-duplex="modelData.BXDate" class="form-control szhl_form_date  szhl_require">
        </div>
    </div>
    <div class="form-group hide">
        <label class="col-xs-2 control-label"><span class="Required">*</span>审核人</label>
        <div class="col-xs-4">
            <select class="form-control">
                <option value="admin">管理员</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">消费记录</label>
        <div class="col-xs-9">
            <table class="table table-bordered table-hover table-hover table-striped">
                <thead>
                    <tr><th>消费类别</th><th>金额</th><th>时间</th><th>事由</th><th>操作</th></tr>
                </thead>
                <tbody>
                    <tr ms-repeat-item="JFBXItemList">
                        <td>{{item.LeiBie}}</td>
                        <td>{{item.BXJE}}</td>
                        <td>{{item.BXDate|date("yyyy-MM-dd")}}</td>
                        <td>{{item.BXContent}}</td>
                        <td><button class="btn btn-danger  btn-xs" ms-if="modelData.CRUser==userName||modelData.CRUser==null" style="margin-left:10px" ms-click="DelItem(item)"> <i class="fa fa-edit"></i>删除</button></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label"><span class="Required">*</span>总金额（元）</label>
        <div class="col-xs-4">
            <input type="text" class="form-control  szhl_require" ms-duplex="modelData.BXZJE" id="inputEmail3">
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">描述</label>
        <div class="col-xs-9">
            <textarea id="conContent" class="span2  form-control" ms-duplex="modelData.BXContent"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">抄送人</label>
        <div class="col-xs-9">
            <input type="text" class="form-control szhl_getPeoples" ms-duplex="modelData.ChaoSongRen" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">附件</label>
        <div class="col-xs-9">
            <input type="text" value="" class="span2  szhl_Upload form-control" ms-duplex="modelData.Files" />
        </div>
    </div>

</div>
<script>
    var tempmodel = avalon.define({
        $id: "JFBX",
        name: "经费报销",

        JFBXItemList: [],
        ItemIDs: ComFunJS.getQueryString("Ids"),
        userName:ComFunJS.getCookie('username'),
        modelData: { "ShenQingRen": ComFunJS.convertuser(ComFunJS.getCookie('username')), "BXDate": "", "BXZJE": "", "BXContent": "", "ChaoSongRen": "", "Files": "", "ChaoSongRen": "", "ItemIds": "" },
        iswf: true,//是否属于流程表单
        inittemp: function (strId) {
            if (strId) {
                //编辑加载数据
                $.getJSON('/API/FTAPI.ashx?Action=GETJFBXMODEL', { P1: strId }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        tempmodel.modelData = resultData.Result;
                        tempmodel.JFBXItemList = resultData.Result1;
                        if (tempmodel.modelData.intProcessStanceid) {
                            pmodel.PIID = tempmodel.modelData.intProcessStanceid;
                        }
                        if (tempmodel.modelData.BXDate && tempmodel.modelData.BXDate.length > 10) {
                            tempmodel.modelData.BXDate = tempmodel.modelData.BXDate.substring(0, 10);
                        }
                        setTimeout(" ComFunJS.initForm()", 500)
                    }
                }) 
            } else {
                tempmodel.modelData.ItemIds = tempmodel.ItemIDs;
                $(".btnSucc").text("送审"); 
                    //获取要报销的经费列表
                    $.getJSON('/API/FTAPI.ashx?Action=GETJFBXITEMBYIDS', { P1: tempmodel.modelData.ItemIds }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            tempmodel.JFBXItemList = resultData.Result;
                            tempmodel.modelData.BXZJE = resultData.Result1;
                            tempmodel.modelData.ItemIds = resultData.Result2;
                            ComFunJS.initForm();
                        }
                    }) 
            }
           
        }, SaveData: function (btdom, piid) {
            var data = tempmodel.modelData.$model;
            if (piid) {
                data.intProcessStanceid = piid;
            }
            var modelValue = JSON.stringify(data);
            $.post("/API/FTAPI.ashx?ACTION=ADDJFBX", { P1: modelValue }, function (result) {
                var jsonresult = $.parseJSON(result)
                btdom.removeClass("disabled").find("i").hide();
                if ($.trim(jsonresult.ErrorMsg) == "") {
                    ComFunJS.winsuccessnew("操作成功");
                }
            });
        },//初始化
        ComputerMoney: function () {
            tempmodel.modelData.BXZJE = 0;
            $(tempmodel.JFBXItemList).each(function (i, val) {
                tempmodel.modelData.BXZJE = parseFloat(tempmodel.modelData.BXZJE) + parseFloat(val.BXJE);
            })
        },
        DelItem: function (item) { //删除经费报销
            tempmodel.JFBXItemList.remove(item);
            var Ids = tempmodel.modelData.ItemIds.split(',');
            ItemId = "";
            $(Ids).each(function (i, val) {
                if (val != item.ID) {
                    ItemId = val + ",";
                }
            })
            ItemId = ItemId.substring(0, ItemId.length - 1);
            tempmodel.modelData.ItemIds = ItemId;
            tempmodel.ComputerMoney();

        }
    })//@ sourceURL=JFBX.js;

</script>
